//
//  NSString+Utilities.m
//  FiveHealth
//
//  Created by JingGuo on 2017/11/29.
//  Copyright © 2017年 com.wukangcheng.FiveHealth. All rights reserved.
//

#import "NSString+Utilities.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (Utilities)

- (NSString *)md5Hash {
    const char *str = [self UTF8String];
    if (str == NULL) {
        str = "";
    }
    unsigned char r[CC_MD5_DIGEST_LENGTH];
    CC_MD5(str, (CC_LONG)strlen(str), r);
    NSString *filename = [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
                          r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]];
    
    return filename;
}

- (BOOL)isMobilePhone
{
    if (!self || [self length] == 0) {
        return NO;
    }
    NSString* mobileRegEx = @"^1[23456789][0-9]{9}$";
    NSPredicate* regExPredicate =
    [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mobileRegEx];
    return [regExPredicate evaluateWithObject:[self lowercaseString]];
}


@end
